<?php
require_once './includes/Start.php';

$serviceId = "";
$repoId = "";
$path = "";
$filter = "";
$bwstype = "";
$file = "";

if( isset( $_GET['serviceid'] ) ) { $serviceId = $_GET['serviceid']; }
if( isset( $_GET['repoid']    ) ) { $repoId    = $_GET['repoid'];    }
if( isset( $_GET['path']      ) ) { $path      = $_GET['path'];      }
if( isset( $_GET['filter']    ) ) { $filter    = $_GET['filter'];    }
if( isset( $_GET['bwstype']   ) ) { $bwstype   = $_GET['bwstype'];   }
if( isset( $_GET['file']      ) ) { $file      = $_GET['file'];   }

if( empty( $serviceId ) or empty( $repoId ) ) {
    include 'template/repo_home.php';
    exit;
}

if( empty( $path ) ) 
    $path = "./";

$repo = $dgConfig->getRepoPath($serviceId, $repoId);
$repoPathBase = (string)$repo;

$svn = new SVNLook($repoPathBase, $_COOKIE["uid"], $_COOKIE["passwd"]);

switch( $bwstype ) {
    case "log";
        $svnloglist = $svn->getSvnLogList($path, $revision);
        include 'template/repo_log_browser.php';
    break;
    case "list";
        $svnlist = $svn->getSvnList($path);
        include 'template/repo_list_browser.php';
    break;
    case "status";
        $svnstatus = $svn->getSvnStatus($path);
        include 'template/repo_status_browser.php';
    break;
    case "diff";
        $target = $path;

        if( !empty( $file ) ) {
            $target = $file;
        }

        $svnResult = $svn->executeSvnCommand($bwstype, $target, "");
        $geshiResult = get_geshi_content($svnResult, $bwstype);
        include 'template/repo_diff_and_cat_browser.php';
    break;
    case "cat";
        $ext  = strrchr($file, ".");
        $mime = $extEnscript[$ext];

        $svnResult = $svn->executeSvnCommand($bwstype, $file, "");

        if( empty( $mime ) ) {
            $geshiResult = $svnResult;
        }
        else {
            $geshiResult = get_geshi_content($svnResult, $mime);
        }

        include 'template/repo_diff_and_cat_browser.php';
    break;
    case "historydiff";
        $svn = new SVNLook(FALSE, $_COOKIE["uid"], $_COOKIE["passwd"]);

        $info = $svn->getResultXmlDom( $svn->executeSvnCommand("info", $repoPathBase, '', "--xml") );
        $reporoot= $info->entry->repository->root;

        $trunk = $reporoot.$repo['trunk'];
        $tags = $reporoot.$repo['tags'];

        if( isset( $_GET['diff'] ) && isset( $_GET['oldid'] ) ) { 
            $diff = $_GET['diff']; 
            $oldid = $_GET['oldid']; 
            if( $diff == "TRUNK" ) {
                $diffpath = "$trunk@HEAD $tags/$oldid@HEAD";
            }
            else {
                $diffpath = "$tags/$diff@HEAD $tags/$oldid@HEAD";
            }

            $diffresult = $svn->getResultXmlDom($svn->executeSvnCommand("diff", $diffpath, '', "--summarize --xml"));

            include 'template/repo_historydiff_result.php';
        }
        else {
            $history = $svn->getSvnList($tags, '', 'desc', false);
            include 'template/repo_historydiff.php';
        }
    break;
}
?>


